// pages/index/seckill/seckill.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    search: '',
    show: '',
    page: 1,
  },

  search: function(e) {
    let search = e.detail.value
    console.log(search)
    let that = this;
    wx.request({
      url: app.globalData.api + "getspikelist",
      data: {
        search: search
      },
      success: function(res) {
        console.log(res)
        if (res.data.list) {
          that.setData({
            list: res.data.list
          })
        } else {
          that.setData({
            list: []
          })
        }
      },
    })
  },
  // 跳系统消息
  jumpmessage() {
    wx.navigateTo({
      url: '/pages/message/message',
    })
  },
  // 跳详情
  jumpdetail: function(e) {
    let id = e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '/pages/goodsDetail/seckillDetail/seckillDetail?id=' + id,
    })
  },
  load(){
    wx.request({
      url: app.globalData.api + "getspikelist",
      data: {
        page: this.data.page
      },
      success: (res) => {
        console.log(res.data.list)
        if (res.data.list.length == 0 && res.data.code == 0) {
          wx.showToast({
            title: '已经到底了',
          })
        } else {
          this.setData({
            list: this.data.list.concat(res.data.list),
            page: ++this.data.page
          })
        }
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.load()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this
    wx.getStorage({
      key: 'userinfo',
      success: function(res) {
        //小红点状态
        wx.request({
          url: app.globalData.api + "getnoticemsg",
          data: {
            uid: res.data.id,
          },
          success: function(res) {
            console.log('小点点', res)
            if (res.data.code == 0) {
              that.setData({
                show: true
              })
            } else {
              that.setData({
                show: false
              })
            }
          },
        })

      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.load()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})